a11y: Skip unlabelled structural roles
authorEmmanuele Bassi <ebassi@gnome.org>
Wed, 11 Nov 2020 17:50:42 +0000 (17:50 +0000)
committerEmmanuele Bassi <ebassi@gnome.org>
Wed, 11 Nov 2020 18:33:15 +0000 (18:33 +0000)
If a structural role is left unlabelled, just leave it unnamed.

gtk/gtkatcontext.c

index 661ac848b1489b93439403b24f04bc6df9440a55..74f368d5e7266926490db633447e0fd10407e065 100644 (file)
@@ -862,6 +862,27 @@ gtk_at_context_get_accessible_relation (GtkATContext          *self,
   return gtk_accessible_attribute_set_get_value (self->relations, relation);
 }
 
+static gboolean
+is_structural_role (GtkAccessibleRole role)
+{
+  /* Keep the switch small while avoiding the compiler warning for
+   * unhandled enumeration values
+   */
+  switch ((int) role)
+    {
+    case GTK_ACCESSIBLE_ROLE_FORM:
+    case GTK_ACCESSIBLE_ROLE_GROUP:
+    case GTK_ACCESSIBLE_ROLE_GENERIC:
+    case GTK_ACCESSIBLE_ROLE_REGION:
+      return TRUE;
+
+    default:
+      break;
+    }
+
+  return FALSE;
+}
+
 /* See the WAI-ARIA ยง 4.3, "Accessible Name and Description Computation" */
 static void
 gtk_at_context_get_name_accumulate (GtkATContext *self,
@@ -937,7 +958,8 @@ gtk_at_context_get_name_accumulate (GtkATContext *self,
   if (names->len != 0)
     return;
 
-  if (self->accessible)
+  /* Ignore structural elements, namely: generic containers */
+  if (self->accessible != NULL && !is_structural_role (role))
     g_ptr_array_add (names, (char *)G_OBJECT_TYPE_NAME (self->accessible));
 }